package com.tedu.lingmaagent.config;

import com.tedu.lingmaagent.store.MongoChatMemoryStore;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MemoryChatAssistantConfiguration {
    @Autowired
    private MongoChatMemoryStore mongoChatMemoryStore;

    /**
     * 创建聊天记忆对象
     * @return
     */
    @Bean
    ChatMemory chatMemory(){
        //设置聊天记忆记录的数量
        return MessageWindowChatMemory.withMaxMessages(10);
    }

    /**
     * 记忆分离
     * @return
     */
    @Bean
    ChatMemoryProvider chatMemoryProvider() {

        return (memoryId) -> MessageWindowChatMemory.builder()
                .id(memoryId).chatMemoryStore(mongoChatMemoryStore)
                .maxMessages(20)
                .build();

    }

}
